<template>
    <a-table :pagination="pagination" :columns :data-source="data" bordered @resizeColumn="resizeColumn"
        :scroll="{ y: 600 }" :row-class-name="(_record, index) => (index % 2 === 1 ? 'table-striped' : null)">
        <template #headerCell="{ column }">
            <template v-if="column.key === 'name'">
                <span>
                    <smile-outlined />
                    Name
                </span>
            </template>
        </template>

        <template #bodyCell="{ column, record, text, index }">
            <template v-if="column.key === 'name'">
                <a-button type="text" danger>
                    {{ text }}
                </a-button>
            </template>
            <template v-else-if="column.key === 'tags'">
                <span>
                    <a-tag v-for="tag in record.tags" :key="tag"
                        :color="tag === 'loser' ? 'volcano' : tag.length > 5 ? 'geekblue' : 'green'">
                        {{ tag.toUpperCase() }}
                    </a-tag>
                </span>
            </template>
            <template v-else-if="column.key === 'action'">
                <a-space :size="10">
                    <a-button type="primary" @click="edit(column)">
                        <template #icon>
                            <EditOutlined />
                        </template>
                        编辑
                    </a-button>

                    <!-- <a-button type="primary" danger @click="edit(column)">
                        <template #icon>
                            <DeleteOutlined />
                        </template>
                        删除
                    </a-button> -->

                    <a-popconfirm title="Are you sure delete this task?" ok-text="Yes" cancel-text="No"
                        @confirm="handleDelete(record)">
                        <a-button type="primary" danger>
                            <template #icon>
                                <DeleteOutlined />
                            </template>
                            删除
                        </a-button>
                    </a-popconfirm>

                </a-space>
            </template>
        </template>
    </a-table>

</template>
<script lang="ts" setup>

import { SmileOutlined, DownOutlined } from '@ant-design/icons-vue';
// import { cloneDeep } from 'lodash-es'
import { message } from 'ant-design-vue';

message.success('tab1')

const resizeColumn = (w, a) => {
    a.width = w
}

const handleDelete = (a) => {

    message.warning(a.name)
}

const edit = (row) => {

}

const columns = [
    {
        name: 'Name',
        dataIndex: 'name',
        key: 'name',
        align: 'center',
        // colSpan: 2,
        resizable: true,
        width: 300
    },
    {
        title: 'Age',
        dataIndex: 'age',
        key: 'age',
        align: 'center',
        // colSpan: 0,

    },
    {
        title: 'Address',
        dataIndex: 'address',
        key: 'address',
        align: 'center',
        width: 300,
        resizable: true,
    },
    {
        title: 'Tags',
        key: 'tags',
        dataIndex: 'tags',
        align: 'center',
        // customCell: (_, index) => ({
        //     rowSpan: index == 0 ? 3 : 0,
        // }),
    },
    {
        title: 'Action',
        key: 'action',
        align: 'center'
    },
];



const data = [
    {
        key: '1',
        name: 'John Brown',
        age: 32,
        address: 'New York No. 1 Lake Park',
        tags: ['nice', 'developer'],

    },
    {
        key: '2',
        name: 'Jim Green',
        age: 42,
        address: 'London No. 1 Lake Park',
        tags: ['loser'],
    },
    {
        key: '3',
        name: 'Joe Black',
        age: 32,
        address: 'Sidney No. 1 Lake Park',
        tags: ['cool', 'teacher'],
    },
    {
        key: '1',
        name: 'John Brown',
        age: 32,
        address: 'New York No. 1 Lake Park',
        tags: ['nice', 'developer'],

    },
    {
        key: '2',
        name: 'Jim Green',
        age: 42,
        address: 'London No. 1 Lake Park',
        tags: ['loser'],
    },
    {
        key: '3',
        name: 'Joe Black',
        age: 32,
        address: 'Sidney No. 1 Lake Park',
        tags: ['cool', 'teacher'],
    },
    {
        key: '1',
        name: 'John Brown',
        age: 32,
        address: 'New York No. 1 Lake Park',
        tags: ['nice', 'developer'],

    },
    {
        key: '2',
        name: 'Jim Green',
        age: 42,
        address: 'London No. 1 Lake Park',
        tags: ['loser'],
    },
    {
        key: '3',
        name: 'Joe Black',
        age: 32,
        address: 'Sidney No. 1 Lake Park',
        tags: ['cool', 'teacher'],
    },
    {
        key: '1',
        name: 'John Brown',
        age: 32,
        address: 'New York No. 1 Lake Park',
        tags: ['nice', 'developer'],

    },
    {
        key: '2',
        name: 'Jim Green',
        age: 42,
        address: 'London No. 1 Lake Park',
        tags: ['loser'],
    },
    {
        key: '3',
        name: 'Joe Black',
        age: 32,
        address: 'Sidney No. 1 Lake Park',
        tags: ['cool', 'teacher'],
    },
    {
        key: '1',
        name: 'John Brown',
        age: 32,
        address: 'New York No. 1 Lake Park',
        tags: ['nice', 'developer'],

    },
    {
        key: '2',
        name: 'Jim Green',
        age: 42,
        address: 'London No. 1 Lake Park',
        tags: ['loser'],
    },
    {
        key: '3',
        name: 'Joe Black',
        age: 32,
        address: 'Sidney No. 1 Lake Park',
        tags: ['cool', 'teacher'],
    },
];

const pagination = {
    // position: ['topRight'],
    total: data.length,
    showTotal: (t) => `共${t}条`,
    'show-size-changer': true,
    'show-quick-jumper': true,
    pageSizeOptions: ['2', '5', '10', '20', '50', '100']

}
</script>